package com.ecloud.gardensterminal.server.scheduling;

import com.ecloud.gardensterminal.dao.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 从数据库定时删除多余数据
 *
 * @author Squbi
 */
@Component
public class DeleteSchedulingService {
    private final Logger logger = LoggerFactory.getLogger(DeleteSchedulingService.class);

    @Autowired
    private GardensParallelingMapper parallelingMapper;
    @Autowired
    private GardensSleetMapper sleetMapper;
    @Autowired
    private GardensSoilMapper soilMapper;
    @Autowired
    private GardensSwitchMapper switchMapper;
    @Autowired
    private GardensWeatherMapper weatherMapper;

    @Scheduled(cron = "0 0/10 * * * ?")
    public void execute() {
        logger.info("starting execute scheduling to delete history data ...");
        parallelingMapper.delete1days();
        switchMapper.delete1days();
        sleetMapper.delete15days();
        soilMapper.delete15days();
        weatherMapper.delete15days();
        logger.info("... scheduling execute complete .");
    }
}
